#include "junix.h"

int main(int argc, char **argv)
{
	if( argc != 2)
		err_quit("Usage:%s file",argv[0]);

	char *p=NULL;
	ssize_t sz;
	mtrace();

	int fd;
	while( (fd=open(argv[1],O_RDONLY))==-1 && errno==EINTR)
	{}

	if(fd==-1)
		err_sys("open");

	FILE *fp = fdopen(fd,"r");
	if( !fd)
		err_quit("fdopen error");

	while( getdelim(&p, &sz,' ', fp) != -1 ){
		fprintf(stdout, "(%s,\t", p);
		fprintf(stdout, "%d)\n", strlen(p));
	}	

	if( ferror(fp) )
		clearerr(fp);
	free (p);

	fcloseall();
    exit(0);
}

